package com.wang.head.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wang.common.pojo.BasePojoEnum;
import com.wang.common.pojo.BaseQuery;
import com.wang.common.util.ConstatFinalUtil;
import com.wang.common.web.controller.BaseController;
import com.wang.users.pojo.AtUsersActivity;
import com.wang.users.pojo.AtUsersActivityQuery;
import com.wang.users.pojo.AtUsersDesc;
import com.wang.users.pojo.AtUsersDescEnum;
import com.wang.users.pojo.AtUsersDescQuery;
import com.wang.users.pojo.AtUsersInvestigate;
import com.wang.users.pojo.AtUsersInvestigateQuery;
import com.wang.users.pojo.AtUsersOrgan;
import com.wang.users.pojo.AtUsersOrganQuery;
import com.wang.users.pojo.AtUsersReport;
import com.wang.users.pojo.AtUsersReportQuery;
import com.wang.users.pojo.AtUsersSchedule;
import com.wang.users.pojo.AtUsersScheduleQuery;
import com.wang.users.service.AtUsersActivityService;
import com.wang.users.service.AtUsersDescService;
import com.wang.users.service.AtUsersInvestigateService;
import com.wang.users.service.AtUsersOperService;
import com.wang.users.service.AtUsersOrganService;
import com.wang.users.service.AtUsersReportService;
import com.wang.users.service.AtUsersScheduleService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;


/**
 * 用户首页操作
 *
 * @author wangsh
 */
@Log4j2
@Controller
@RequestMapping("/head/users/")
public class UsersHeadController extends BaseController {
    @Autowired
    private AtUsersDescService usersDescService;
    @Autowired
    private AtUsersScheduleService usersScheduleService;
    @Autowired
    private AtUsersActivityService usersActivityService;
    @Autowired
    private AtUsersInvestigateService usersInvestigateService;
    @Autowired
    private AtUsersReportService usersReportService;
    @Autowired
    private AtUsersOperService usersOperService;
    @Autowired
    private AtUsersOrganService usersOrganService;

    /**
     * 首页
     *
     * @return
     */
    @RequestMapping("/main")
    public String main(HttpServletRequest request, Model model) {
        log.info("--main--");
        AtUsersDesc usersSess = (AtUsersDesc) this.findObjFromSession(request, BasePojoEnum.SESS_USERS);
        if (StringUtils.isEmpty(usersSess.getId())) {
            return "redirect:/login";
        }
        AtUsersDescQuery paramQuery = new AtUsersDescQuery();
        AtUsersDesc entity = paramQuery.getEntity();
        entity.setId(usersSess.getId());
        AtUsersDesc one = this.usersDescService.findOne(paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, one);
        return "head/users/main";
    }

    /**
     * 欢迎页面
     *
     * @return
     */
    @RequestMapping("/welcome")
    public String welcome() {
        log.info("--welcome--");
        return "head/users/welcome";
    }

    /**
     * 打开用户更新
     *
     * @return
     */
    @RequestMapping("/usersUpdate")
    public String usersUpdate(HttpServletRequest request, AtUsersDescQuery paramQuery,Model model) {
        log.info("--usersUpdate--");

        /* 从session中获取信息 */
        AtUsersDesc one = (AtUsersDesc) this.findObjFromSession(request, BasePojoEnum.SESS_USERS);
        AtUsersDesc entity = paramQuery.getEntity();
        entity.setId(one.getId());
        one = this.usersDescService.findOne(paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, one);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PARAMQUERY, paramQuery);
        if ("updateInfo".equalsIgnoreCase(paramQuery.getOperType())) {
            /* 根据不同的请求跳转不同的页面 */
            return "head/users/usersUpdateInfo";
        } else if ("updatePass".equalsIgnoreCase(paramQuery.getOperType())) {
            /* 根据不同的请求跳转不同的页面 */
            return "head/users/usersUpdatePass";
        }
        return "head/users/usersInfo";
    }

    /**
     * 打开用户提交
     *
     * @return
     */
    @RequestMapping("/usersUpdateSubmit")
    public String usersUpdateSubmit(HttpServletRequest request,AtUsersDescQuery paramQuery, Model model) {
        log.info("--usersUpdateSubmit--");
        AtUsersDesc users = (AtUsersDesc) this.findObjFromSession(request, BasePojoEnum.SESS_USERS);
        /* 从session中获取信息 */
        AtUsersDesc one = (AtUsersDesc) this.findObjFromSession(request, BasePojoEnum.SESS_USERS);
        AtUsersDesc entityCond = paramQuery.getEntity();
        entityCond.setId(one.getId());
        one = this.usersDescService.findOne(paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, one);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PARAMQUERY, paramQuery);
        if (BaseQuery.FINAL_OPER_UPDATE.equalsIgnoreCase(paramQuery.getOperType())) {
            AtUsersDesc entity = paramQuery.getEntity();

            boolean dbFlag = this.usersDescService.updateById(entity);
            JSONObject resultJson = this.proccedResponseJson(dbFlag);
            log.info("==dbFlag=={}", dbFlag);
            model.addAttribute(ConstatFinalUtil.FINAL_RESPONSE, resultJson);
            return "head/users/usersUpdateInfo";
        }
        return "head/users/usersInfo";
    }

    /**
     * 退出页面
     *
     * @return
     */
    @RequestMapping("/logout")
    public String logout(HttpServletRequest request, HttpSession session) {
        log.info("--logout--");
        /* 获取用户 */
        /* 删除 */
        session.removeAttribute(BasePojoEnum.SESS_USERS.getCode());
        session.removeAttribute("lastLoginTime");
        /* 客户端跳转到登陆页面 */
        return "redirect:/login";
    }

    /**
     * 周日程管理查询多条
     *
     * @return
     */
    @RequestMapping("/scheduleList")
    public String scheduleList(AtUsersScheduleQuery paramQuery, Model model, HttpServletRequest request) {
        log.info("==周日程管理列表==");
        AtUsersDesc usersDescSess = (AtUsersDesc) this.findObjFromSession(request, BasePojoEnum.SESS_USERS);
        /* 分页对象 */
        IPage<AtUsersSchedule> paramPage = null;
        try {
            paramPage = new Page<>(paramQuery.getCurrent(), paramQuery.getSize());
        } catch (Exception e) {
            paramPage = new Page<>(1, 20);
        }
        /* 时间处理 */
        if (StringUtils.isNotEmpty(paramQuery.getStDate())) {
            paramQuery.setPubTimeSt(this.dateUtil.strToDateTime(paramQuery.getStDate()));
        }
        paramQuery.addLike();

        /* 增加条件 */
        AtUsersSchedule entity = paramQuery.getEntity();
        entity.setUsersId(usersDescSess.getId());

        /* 查询对象 */
        List<AtUsersSchedule> dataList = this.usersScheduleService.findList(paramPage, paramQuery);
        paramQuery.removeLike();
        /* 列表数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_DATALIST, dataList);
        /* 分页数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PAGEINFOUTIL, paramPage);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PARAMQUERY, paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ENUMSONE, new AtUsersSchedule());
        /* 查询数据 */
        return "head/users/scheduleList";
    }

    /**
     * 周日程管理打开添加页面
     * 更新和详情是同一个页面;
     *
     * @return
     */
    @RequestMapping("/scheduleInsert")
    public String scheduleInsert(AtUsersScheduleQuery paramQuery, Model model, HttpServletRequest request) {
        log.info("==周日程管理添加==");
        AtUsersSchedule entity = paramQuery.getEntity();
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, entity);
        /* 查询用户(领导列表) */
        AtUsersDescQuery usersDescQuery = new AtUsersDescQuery();
        AtUsersDesc usersEntity = usersDescQuery.getEntity();
        usersEntity.setUsersType(AtUsersDescEnum.USERSTYPE_LEADER.getCode());
        List<AtUsersDesc> dataList = this.usersDescService.findList(null, usersDescQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_USERS_LEADER_LIST, dataList);

        /* 查询用户(领导列表) */
        usersDescQuery = new AtUsersDescQuery();
        usersEntity = usersDescQuery.getEntity();
        List<AtUsersDesc> userDataList = this.usersDescService.findList(null, usersDescQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_USERS_LIST, userDataList);
        /* 查询数据 */
        return "head/users/scheduleInsert";
    }

    /**
     * 周日程管理打开更新页面
     * 更新和详情是同一个页面;
     *
     * @return
     */
    @RequestMapping("/scheduleInsertSubmit")
    public String scheduleInsertSubmit(AtUsersScheduleQuery paramQuery, Model model, HttpServletRequest request) {
        log.info("==周日程管理添加提交==");
        AtUsersSchedule entity = paramQuery.getEntity();
        /* 从session中获取信息 */
        AtUsersDesc one = (AtUsersDesc) this.findObjFromSession(request, BasePojoEnum.SESS_USERS);
        if (Objects.nonNull(one)) {
            entity.setUsersId(one.getId());
        }
        if(StringUtils.isNotEmpty(paramQuery.getCurrDate())) {
            entity.setCurrDate(this.dateUtil.strToDate(paramQuery.getCurrDate()));
        }
        if(StringUtils.isNotEmpty(paramQuery.getProccedEndTime())) {
            entity.setProccedEndTime(this.dateUtil.strToDateTime(paramQuery.getProccedEndTime()));
        }
        boolean dbFlag = this.usersScheduleService.save(entity);
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        model.addAttribute(ConstatFinalUtil.FINAL_RESPONSE, resultJson);
        /* 查询数据 */
        return this.scheduleInsert(paramQuery, model, request);
    }

    /**
     * 周日程管理打开更新页面
     * 更新和详情是同一个页面;
     *
     * @return
     */
    @RequestMapping("/scheduleUpdate")
    public String scheduleUpdate(AtUsersScheduleQuery paramQuery, Model model) {
        log.info("==周日程管理更新==");
        /* 根据id查询 */
        AtUsersSchedule one = this.usersScheduleService.findOne(paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, one);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PARAMQUERY, paramQuery);
        if (BaseQuery.FINAL_OPER_UPDATE.equalsIgnoreCase(paramQuery.getOperType())) {

            /* 查询用户(领导列表) */
            AtUsersDescQuery usersDescQuery = new AtUsersDescQuery();
            AtUsersDesc usersEntity = usersDescQuery.getEntity();
            usersEntity.setUsersType(AtUsersDescEnum.USERSTYPE_LEADER.getCode());
            List<AtUsersDesc> dataList = this.usersDescService.findList(null, usersDescQuery);
            model.addAttribute(ConstatFinalUtil.FINAL_CODE_USERS_LEADER_LIST, dataList);

            /* 查询用户(领导列表) */
            usersDescQuery = new AtUsersDescQuery();
            usersEntity = usersDescQuery.getEntity();
            List<AtUsersDesc> userDataList = this.usersDescService.findList(null, usersDescQuery);
            model.addAttribute(ConstatFinalUtil.FINAL_CODE_USERS_LIST, userDataList);

            /* 查询数据 */
            return "head/users/scheduleUpdate";
        }
        /* 查询数据 */
        return "head/users/scheduleInfo";
    }

    /**
     * 周日程管理打开更新页面
     * 更新和详情是同一个页面;
     *
     * @return
     */
    @RequestMapping("/scheduleUpdateSubmit")
    public String scheduleUpdateSubmit(AtUsersScheduleQuery paramQuery, Model model) {
        log.info("==周日程管理更新提交==");
        AtUsersSchedule entity = paramQuery.getEntity();
        if (StringUtils.isNotEmpty(paramQuery.getPubTime())) {
            entity.setPubTime(this.dateUtil.strToDateTime(paramQuery.getPubTime()));
        }
        if(StringUtils.isNotEmpty(paramQuery.getCurrDate())) {
            entity.setCurrDate(this.dateUtil.strToDate(paramQuery.getCurrDate()));
        }
        if(StringUtils.isNotEmpty(paramQuery.getProccedEndTime())) {
            entity.setProccedEndTime(this.dateUtil.strToDateTime(paramQuery.getProccedEndTime()));
        }
        /* 根据id查询 */
        boolean dbFlag = this.usersScheduleService.updateById(entity);
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        model.addAttribute(ConstatFinalUtil.FINAL_RESPONSE, resultJson);
        /* 查询数据 */
        return this.scheduleUpdate(paramQuery, model);
    }

    /**
     * 批量操作
     * @param paramQuery    操作的条件
     * @param model 存储对象
     * @return  返回json数据
     */
    @RequestMapping("/scheduleBatch")
    @ResponseBody
    public String scheduleBatch(AtUsersScheduleQuery paramQuery, Model model) {
        log.info("==周日程管理批量操作==");
        String operType = paramQuery.getOperType();
        String[] ids = paramQuery.getIds();
        String info = ConstatFinalUtil.FINAL_OPER_SUCCESS;
        int totalCount = 0;
        int succedCount = 0;
        int failedCount = 0;
        if (StringUtils.isNotEmpty(operType)) {
            if (Objects.nonNull(ids) && ids.length > 0) {
                totalCount = ids.length;
                for (String idTemp : ids) {
                    try {
                        AtUsersScheduleQuery paramQueryTemp = new AtUsersScheduleQuery();
                        AtUsersSchedule entity = paramQueryTemp.getEntity();
                        entity.setId(idTemp);
                        /* 根据id查询每一个 记录对象 */
                        AtUsersSchedule dataDbResult = this.usersScheduleService.findOne(paramQueryTemp);
                        if (dataDbResult != null) {
                            boolean dbFlag = false;
                            /* 催办 */
                            if (BaseQuery.FINAL_OPER_UPDATE_URGING.equalsIgnoreCase(operType)) {
                                /* 批量修改状态 */
                                dataDbResult.setUrgingNum(dataDbResult.getUrgingNum() + 1);
                                dbFlag = this.usersScheduleService.updateById(dataDbResult);
                            }
                            if (dbFlag) {
                                succedCount ++;
                            } else {
                                failedCount ++;
                            }
                        }
                    } catch (Exception e) {
                        log.error("批量操作失败了,id:{}", idTemp, e);
                        failedCount ++;
                    }
                }
            } else {
                /* 未选择类型,ids */
                info = "ids为空";
            }
        } else {
            /* 操作类型未选择 */
            info = "操作类型未选择";
        }

        String messInfo = "批量操作日志:提示信息:${info}, 总条数:${totalCount},成功条数:${succedCount},失败条数:${failedCount}";
        Map<String,String> paramsMap = new HashMap<>(1);
        paramsMap.put("info", info);
        paramsMap.put("totalCount", String.valueOf(totalCount));
        paramsMap.put("succedCount", String.valueOf(succedCount));
        paramsMap.put("failedCount", String.valueOf(failedCount));
        messInfo = this.regexUtil.replaceOperator(messInfo, paramsMap);

        paramsMap = new HashMap<>(1);
        paramsMap.put(ConstatFinalUtil.FINAL_CONFIG_INFO_SUCCESS_PARAM1, messInfo);
        /* 查询数据 */
        JSONObject resultJson = this.proccedResponseJson(ConstatFinalUtil.FINAL_OPER_SUCCESS.equalsIgnoreCase(info), paramsMap);
        log.info("==结果:{}==", resultJson);
        return resultJson.toJSONString();
    }

    /**
     * 外事登记查询多条
     *
     * @return
     */
    @RequestMapping("/activityList")
    public String activityList(AtUsersActivityQuery paramQuery, Model model, HttpServletRequest request) {
        log.info("==外事登记列表==");
        AtUsersDesc usersDescSess = (AtUsersDesc) this.findObjFromSession(request, BasePojoEnum.SESS_USERS);
        /* 分页对象 */
        IPage<AtUsersActivity> paramPage = null;
        try {
            paramPage = new Page<>(paramQuery.getCurrent(), paramQuery.getSize());
        } catch (Exception e) {
            paramPage = new Page<>(1, 20);
        }
        /* 时间处理 */
        if (StringUtils.isNotEmpty(paramQuery.getStDate())) {
            paramQuery.setPubTimeSt(this.dateUtil.strToDateTime(paramQuery.getStDate()));
        }
        paramQuery.addLike();

        /* 增加条件 */
        AtUsersActivity entity = paramQuery.getEntity();
        entity.setUsersId(usersDescSess.getId());

        /* 查询对象 */
        List<AtUsersActivity> dataList = this.usersActivityService.findList(paramPage, paramQuery);
        paramQuery.removeLike();
        /* 列表数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_DATALIST, dataList);
        /* 分页数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PAGEINFOUTIL, paramPage);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PARAMQUERY, paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ENUMSONE, new AtUsersActivity());
        /* 查询数据 */
        return "head/users/activityList";
    }

    /**
     * 外事登记打开添加页面
     * 更新和详情是同一个页面;
     *
     * @return
     */
    @RequestMapping("/activityInsert")
    public String activityInsert(AtUsersActivityQuery paramQuery, Model model, HttpServletRequest request) {
        log.info("==外事登记添加==");
        AtUsersActivity entity = paramQuery.getEntity();
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, entity);
        /* 查询用户(领导列表) */
        AtUsersDescQuery usersDescQuery = new AtUsersDescQuery();
        AtUsersDesc usersEntity = usersDescQuery.getEntity();
        usersEntity.setUsersType(AtUsersDescEnum.USERSTYPE_LEADER.getCode());
        List<AtUsersDesc> dataList = this.usersDescService.findList(null, usersDescQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_USERS_LEADER_LIST, dataList);

        AtUsersOrganQuery organQuery = new AtUsersOrganQuery();
        AtUsersOrgan organEntity = organQuery.getEntity();
        organEntity.setStatus(BasePojoEnum.STATUS_ENABLE.getCode());
        organEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
        /* 查询对象 */
        List<AtUsersOrgan> organDataList = this.usersOrganService.findList(null, organQuery);
        paramQuery.removeLike();
        JSONArray treeArr = this.usersOperService.treeJson(organDataList);
        /* 列表数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ORGAN_LIST, treeArr.toJSONString());

        /* 查询数据 */
        return "head/users/activityInsert";
    }

    /**
     * 外事登记打开更新页面
     * 更新和详情是同一个页面;
     *
     * @return
     */
    @RequestMapping("/activityInsertSubmit")
    public String activityInsertSubmit(AtUsersActivityQuery paramQuery, Model model, HttpServletRequest request) {
        log.info("==外事登记添加提交==");
        AtUsersActivity entity = paramQuery.getEntity();
        /* 从session中获取信息 */
        AtUsersDesc one = (AtUsersDesc) this.findObjFromSession(request, BasePojoEnum.SESS_USERS);
        if (Objects.nonNull(one)) {
            entity.setUsersId(one.getId());
        }
        if(StringUtils.isNotEmpty(paramQuery.getCurrDate())) {
            entity.setCurrDate(this.dateUtil.strToDateTime(paramQuery.getCurrDate()));
        }
        if(StringUtils.isNotEmpty(paramQuery.getBackDate())) {
            entity.setBackDate(this.dateUtil.strToDateTime(paramQuery.getBackDate()));
        }
        if(StringUtils.isNotEmpty(paramQuery.getProccedEndTime())) {
            entity.setProccedEndTime(this.dateUtil.strToDateTime(paramQuery.getProccedEndTime()));
        }
        boolean dbFlag = this.usersActivityService.save(entity);
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        model.addAttribute(ConstatFinalUtil.FINAL_RESPONSE, resultJson);
        /* 查询数据 */
        return this.activityInsert(paramQuery, model, request);
    }

    /**
     * 外事登记打开更新页面
     * 更新和详情是同一个页面;
     *
     * @return
     */
    @RequestMapping("/activityUpdate")
    public String activityUpdate(AtUsersActivityQuery paramQuery, Model model) {
        log.info("==外事登记更新==");
        /* 根据id查询 */
        AtUsersActivity one = this.usersActivityService.findOne(paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, one);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PARAMQUERY, paramQuery);
        if (BaseQuery.FINAL_OPER_UPDATE.equalsIgnoreCase(paramQuery.getOperType())) {

            /* 查询用户(领导列表) */
            AtUsersDescQuery usersDescQuery = new AtUsersDescQuery();
            AtUsersDesc usersEntity = usersDescQuery.getEntity();
            usersEntity.setUsersType(AtUsersDescEnum.USERSTYPE_LEADER.getCode());
            List<AtUsersDesc> dataList = this.usersDescService.findList(null, usersDescQuery);
            model.addAttribute(ConstatFinalUtil.FINAL_CODE_USERS_LEADER_LIST, dataList);

            AtUsersOrganQuery organQuery = new AtUsersOrganQuery();
            AtUsersOrgan organEntity = organQuery.getEntity();
            organEntity.setStatus(BasePojoEnum.STATUS_ENABLE.getCode());
            organEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
            /* 查询对象 */
            List<AtUsersOrgan> organDataList = this.usersOrganService.findList(null, organQuery);
            paramQuery.removeLike();
            JSONArray treeArr = this.usersOperService.treeJson(organDataList);
            /* 列表数据 */
            model.addAttribute(ConstatFinalUtil.FINAL_CODE_ORGAN_LIST, treeArr.toJSONString());

            /* 查询数据 */
            return "head/users/activityUpdate";
        }
        /* 查询数据 */
        return "head/users/activityInfo";
    }

    /**
     * 外事登记打开更新页面
     * 更新和详情是同一个页面;
     *
     * @return
     */
    @RequestMapping("/activityUpdateSubmit")
    public String activityUpdateSubmit(AtUsersActivityQuery paramQuery, Model model) {
        log.info("==外事登记更新提交==");
        AtUsersActivity entity = paramQuery.getEntity();
        if (StringUtils.isNotEmpty(paramQuery.getPubTime())) {
            entity.setPubTime(this.dateUtil.strToDateTime(paramQuery.getPubTime()));
        }
        if(StringUtils.isNotEmpty(paramQuery.getCurrDate())) {
            entity.setCurrDate(this.dateUtil.strToDateTime(paramQuery.getCurrDate()));
        }
        if(StringUtils.isNotEmpty(paramQuery.getBackDate())) {
            entity.setBackDate(this.dateUtil.strToDateTime(paramQuery.getBackDate()));
        }
        if(StringUtils.isNotEmpty(paramQuery.getProccedEndTime())) {
            entity.setProccedEndTime(this.dateUtil.strToDateTime(paramQuery.getProccedEndTime()));
        }
        /* 根据id查询 */
        boolean dbFlag = this.usersActivityService.updateById(entity);
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        model.addAttribute(ConstatFinalUtil.FINAL_RESPONSE, resultJson);
        /* 查询数据 */
        return this.activityUpdate(paramQuery, model);
    }

    /**
     * 批量操作
     * @param paramQuery    操作的条件
     * @param model 存储对象
     * @return  返回json数据
     */
    @RequestMapping("/activityBatch")
    @ResponseBody
    public String activityBatch(AtUsersScheduleQuery paramQuery, Model model) {
        log.info("==外事登记批量操作==");
        String operType = paramQuery.getOperType();
        String[] ids = paramQuery.getIds();
        String info = ConstatFinalUtil.FINAL_OPER_SUCCESS;
        int totalCount = 0;
        int succedCount = 0;
        int failedCount = 0;
        if (StringUtils.isNotEmpty(operType)) {
            if (Objects.nonNull(ids) && ids.length > 0) {
                totalCount = ids.length;
                for (String idTemp : ids) {
                    try {
                        AtUsersActivityQuery paramQueryTemp = new AtUsersActivityQuery();
                        AtUsersActivity entity = paramQueryTemp.getEntity();
                        entity.setId(idTemp);
                        /* 根据id查询每一个 记录对象 */
                        AtUsersActivity dataDbResult = this.usersActivityService.findOne(paramQueryTemp);
                        if (dataDbResult != null) {
                            boolean dbFlag = false;
                            /* 催办 */
                            if (BaseQuery.FINAL_OPER_UPDATE_URGING.equalsIgnoreCase(operType)) {
                                /* 批量修改状态 */
                                dataDbResult.setUrgingNum(dataDbResult.getUrgingNum() + 1);
                                dbFlag = this.usersActivityService.updateById(dataDbResult);
                            }
                            if (dbFlag) {
                                succedCount ++;
                            } else {
                                failedCount ++;
                            }
                        }
                    } catch (Exception e) {
                        log.error("批量操作失败了,id:{}", idTemp, e);
                        failedCount ++;
                    }
                }
            } else {
                /* 未选择类型,ids */
                info = "ids为空";
            }
        } else {
            /* 操作类型未选择 */
            info = "操作类型未选择";
        }

        String messInfo = "批量操作日志:提示信息:${info}, 总条数:${totalCount},成功条数:${succedCount},失败条数:${failedCount}";
        Map<String,String> paramsMap = new HashMap<>(1);
        paramsMap.put("info", info);
        paramsMap.put("totalCount", String.valueOf(totalCount));
        paramsMap.put("succedCount", String.valueOf(succedCount));
        paramsMap.put("failedCount", String.valueOf(failedCount));
        messInfo = this.regexUtil.replaceOperator(messInfo, paramsMap);

        paramsMap = new HashMap<>(1);
        paramsMap.put(ConstatFinalUtil.FINAL_CONFIG_INFO_SUCCESS_PARAM1, messInfo);
        /* 查询数据 */
        JSONObject resultJson = this.proccedResponseJson(ConstatFinalUtil.FINAL_OPER_SUCCESS.equalsIgnoreCase(info), paramsMap);
        log.info("==结果:{}==", resultJson);
        return resultJson.toJSONString();
    }

    /**
     * 考察报告查询多条
     *
     * @return
     */
    @RequestMapping("/reportList")
    public String reportList(AtUsersReportQuery paramQuery, Model model, HttpServletRequest request) {
        log.info("==考察报告列表==");
        AtUsersDesc usersDescSess = (AtUsersDesc) this.findObjFromSession(request, BasePojoEnum.SESS_USERS);
        /* 分页对象 */
        IPage<AtUsersReport> paramPage = null;
        try {
            paramPage = new Page<>(paramQuery.getCurrent(), paramQuery.getSize());
        } catch (Exception e) {
            paramPage = new Page<>(1, 20);
        }
        /* 时间处理 */
        if (StringUtils.isNotEmpty(paramQuery.getStDate())) {
            paramQuery.setPubTimeSt(this.dateUtil.strToDateTime(paramQuery.getStDate()));
        }
        paramQuery.addLike();

        /* 增加条件 */
        AtUsersReport entity = paramQuery.getEntity();
        entity.setUsersId(usersDescSess.getId());

        /* 查询对象 */
        List<AtUsersReport> dataList = this.usersReportService.findList(paramPage, paramQuery);
        paramQuery.removeLike();
        /* 列表数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_DATALIST, dataList);
        /* 分页数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PAGEINFOUTIL, paramPage);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PARAMQUERY, paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ENUMSONE, new AtUsersReport());
        /* 查询数据 */
        return "head/users/reportList";
    }

    /**
     * 考察报告打开添加页面
     * 更新和详情是同一个页面;
     *
     * @return
     */
    @RequestMapping("/reportInsert")
    public String reportInsert(AtUsersReportQuery paramQuery, Model model, HttpServletRequest request) {
        log.info("==考察报告添加==");
        AtUsersReport entity = paramQuery.getEntity();
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, entity);
        /* 查询用户(领导列表) */
        AtUsersDescQuery usersDescQuery = new AtUsersDescQuery();
        AtUsersDesc usersEntity = usersDescQuery.getEntity();
        usersEntity.setUsersType(AtUsersDescEnum.USERSTYPE_LEADER.getCode());
        List<AtUsersDesc> dataList = this.usersDescService.findList(null, usersDescQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_USERS_LEADER_LIST, dataList);

        /* 查询数据 */
        return "head/users/reportInsert";
    }

    /**
     * 考察报告打开更新页面
     * 更新和详情是同一个页面;
     *
     * @return
     */
    @RequestMapping("/reportInsertSubmit")
    public String reportInsertSubmit(AtUsersReportQuery paramQuery, Model model, HttpServletRequest request) {
        log.info("==考察报告添加提交==");
        AtUsersReport entity = paramQuery.getEntity();
        /* 从session中获取信息 */
        AtUsersDesc one = (AtUsersDesc) this.findObjFromSession(request, BasePojoEnum.SESS_USERS);
        if (Objects.nonNull(one)) {
            entity.setUsersId(one.getId());
        }
        if(StringUtils.isNotEmpty(paramQuery.getStartTime())) {
            entity.setStartTime(this.dateUtil.strToDateTime(paramQuery.getStartTime()));
        }
        if(StringUtils.isNotEmpty(paramQuery.getEndTime())) {
            entity.setEndTime(this.dateUtil.strToDateTime(paramQuery.getEndTime()));
        }
        if(StringUtils.isNotEmpty(paramQuery.getProccedEndTime())) {
            entity.setProccedEndTime(this.dateUtil.strToDateTime(paramQuery.getProccedEndTime()));
        }
        boolean dbFlag = this.usersReportService.save(entity);
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        model.addAttribute(ConstatFinalUtil.FINAL_RESPONSE, resultJson);
        /* 查询数据 */
        return this.reportInsert(paramQuery, model, request);
    }

    /**
     * 考察报告打开更新页面
     * 更新和详情是同一个页面;
     *
     * @return
     */
    @RequestMapping("/reportUpdate")
    public String reportUpdate(AtUsersReportQuery paramQuery, Model model) {
        log.info("==考察报告更新==");
        /* 根据id查询 */
        AtUsersReport one = this.usersReportService.findOne(paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, one);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PARAMQUERY, paramQuery);
        if (BaseQuery.FINAL_OPER_UPDATE.equalsIgnoreCase(paramQuery.getOperType())) {

            /* 查询用户(领导列表) */
            AtUsersDescQuery usersDescQuery = new AtUsersDescQuery();
            AtUsersDesc usersEntity = usersDescQuery.getEntity();
            usersEntity.setUsersType(AtUsersDescEnum.USERSTYPE_LEADER.getCode());
            List<AtUsersDesc> dataList = this.usersDescService.findList(null, usersDescQuery);
            model.addAttribute(ConstatFinalUtil.FINAL_CODE_USERS_LEADER_LIST, dataList);

            /* 查询数据 */
            return "head/users/reportUpdate";
        }
        /* 查询数据 */
        return "head/users/reportInfo";
    }

    /**
     * 考察报告打开更新页面
     * 更新和详情是同一个页面;
     *
     * @return
     */
    @RequestMapping("/reportUpdateSubmit")
    public String reportUpdateSubmit(AtUsersReportQuery paramQuery, Model model) {
        log.info("==考察报告更新提交==");
        AtUsersReport entity = paramQuery.getEntity();
        if (StringUtils.isNotEmpty(paramQuery.getPubTime())) {
            entity.setPubTime(this.dateUtil.strToDateTime(paramQuery.getPubTime()));
        }
        if(StringUtils.isNotEmpty(paramQuery.getStartTime())) {
            entity.setStartTime(this.dateUtil.strToDateTime(paramQuery.getStartTime()));
        }
        if(StringUtils.isNotEmpty(paramQuery.getEndTime())) {
            entity.setEndTime(this.dateUtil.strToDateTime(paramQuery.getEndTime()));
        }
        if(StringUtils.isNotEmpty(paramQuery.getProccedEndTime())) {
            entity.setProccedEndTime(this.dateUtil.strToDateTime(paramQuery.getProccedEndTime()));
        }
        /* 根据id查询 */
        boolean dbFlag = this.usersReportService.updateById(entity);
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        model.addAttribute(ConstatFinalUtil.FINAL_RESPONSE, resultJson);
        /* 查询数据 */
        return this.reportUpdate(paramQuery, model);
    }

    /**
     * 考察行程查询多条
     *
     * @return
     */
    @RequestMapping("/investigateList")
    public String investigateList(AtUsersInvestigateQuery paramQuery, Model model, HttpServletRequest request) {
        log.info("==考察行程列表==");
        AtUsersDesc usersDescSess = (AtUsersDesc) this.findObjFromSession(request, BasePojoEnum.SESS_USERS);
        /* 分页对象 */
        IPage<AtUsersInvestigate> paramPage = null;
        try {
            paramPage = new Page<>(paramQuery.getCurrent(), paramQuery.getSize());
        } catch (Exception e) {
            paramPage = new Page<>(1, 20);
        }
        /* 时间处理 */
        if (StringUtils.isNotEmpty(paramQuery.getStDate())) {
            paramQuery.setPubTimeSt(this.dateUtil.strToDateTime(paramQuery.getStDate()));
        }
        paramQuery.addLike();

        /* 增加条件 */
        AtUsersInvestigate entity = paramQuery.getEntity();
        entity.setUsersId(usersDescSess.getId());

        /* 查询对象 */
        List<AtUsersInvestigate> dataList = this.usersInvestigateService.findList(paramPage, paramQuery);
        paramQuery.removeLike();
        /* 列表数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_DATALIST, dataList);
        /* 分页数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PAGEINFOUTIL, paramPage);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PARAMQUERY, paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ENUMSONE, new AtUsersInvestigate());
        /* 查询数据 */
        return "head/users/investigateList";
    }

    /**
     * 考察行程打开添加页面
     * 更新和详情是同一个页面;
     *
     * @return
     */
    @RequestMapping("/investigateInsert")
    public String investigateInsert(AtUsersInvestigateQuery paramQuery, Model model, HttpServletRequest request) {
        log.info("==考察行程添加==");
        AtUsersInvestigate entity = paramQuery.getEntity();
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, entity);
        /* 查询用户(领导列表) */
        AtUsersDescQuery usersDescQuery = new AtUsersDescQuery();
        AtUsersDesc usersEntity = usersDescQuery.getEntity();
        usersEntity.setUsersType(AtUsersDescEnum.USERSTYPE_LEADER.getCode());
        List<AtUsersDesc> dataList = this.usersDescService.findList(null, usersDescQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_USERS_LEADER_LIST, dataList);

        /* 查询用户(领导列表) */
        usersDescQuery = new AtUsersDescQuery();
        usersEntity = usersDescQuery.getEntity();
        List<AtUsersDesc> userDataList = this.usersDescService.findList(null, usersDescQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_USERS_LIST, userDataList);

        /* 查询数据 */
        return "head/users/investigateInsert";
    }

    /**
     * 考察行程打开更新页面
     * 更新和详情是同一个页面;
     *
     * @return
     */
    @RequestMapping("/investigateInsertSubmit")
    public String investigateInsertSubmit(AtUsersInvestigateQuery paramQuery, Model model, HttpServletRequest request) {
        log.info("==考察行程添加提交==");
        AtUsersInvestigate entity = paramQuery.getEntity();
        /* 从session中获取信息 */
        AtUsersDesc one = (AtUsersDesc) this.findObjFromSession(request, BasePojoEnum.SESS_USERS);
        if (Objects.nonNull(one)) {
            entity.setUsersId(one.getId());
        }
        if(StringUtils.isNotEmpty(paramQuery.getProccedEndTime())) {
            entity.setProccedEndTime(this.dateUtil.strToDateTime(paramQuery.getProccedEndTime()));
        }
        boolean dbFlag = this.usersInvestigateService.save(entity);
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        model.addAttribute(ConstatFinalUtil.FINAL_RESPONSE, resultJson);
        /* 查询数据 */
        return this.investigateInsert(paramQuery, model, request);
    }

    /**
     * 考察行程打开更新页面
     * 更新和详情是同一个页面;
     *
     * @return
     */
    @RequestMapping("/investigateUpdate")
    public String investigateUpdate(AtUsersInvestigateQuery paramQuery, Model model) {
        log.info("==考察行程更新==");
        /* 根据id查询 */
        AtUsersInvestigate one = this.usersInvestigateService.findOne(paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, one);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PARAMQUERY, paramQuery);
        if (BaseQuery.FINAL_OPER_UPDATE.equalsIgnoreCase(paramQuery.getOperType())) {

            /* 查询用户(领导列表) */
            AtUsersDescQuery usersDescQuery = new AtUsersDescQuery();
            AtUsersDesc usersEntity = usersDescQuery.getEntity();
            usersEntity.setUsersType(AtUsersDescEnum.USERSTYPE_LEADER.getCode());
            List<AtUsersDesc> dataList = this.usersDescService.findList(null, usersDescQuery);
            model.addAttribute(ConstatFinalUtil.FINAL_CODE_USERS_LEADER_LIST, dataList);

            /* 查询用户(领导列表) */
            usersDescQuery = new AtUsersDescQuery();
            usersEntity = usersDescQuery.getEntity();
            List<AtUsersDesc> userDataList = this.usersDescService.findList(null, usersDescQuery);
            model.addAttribute(ConstatFinalUtil.FINAL_CODE_USERS_LIST, userDataList);

            /* 查询数据 */
            return "head/users/investigateUpdate";
        }
        /* 查询数据 */
        return "head/users/investigateInfo";
    }

    /**
     * 考察行程打开更新页面
     * 更新和详情是同一个页面;
     *
     * @return
     */
    @RequestMapping("/investigateUpdateSubmit")
    public String investigateUpdateSubmit(AtUsersInvestigateQuery paramQuery, Model model) {
        log.info("==考察行程更新提交==");
        AtUsersInvestigate entity = paramQuery.getEntity();
        if (StringUtils.isNotEmpty(paramQuery.getPubTime())) {
            entity.setPubTime(this.dateUtil.strToDateTime(paramQuery.getPubTime()));
        }
        if(StringUtils.isNotEmpty(paramQuery.getProccedEndTime())) {
            entity.setProccedEndTime(this.dateUtil.strToDateTime(paramQuery.getProccedEndTime()));
        }
        /* 根据id查询 */
        boolean dbFlag = this.usersInvestigateService.updateById(entity);
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        model.addAttribute(ConstatFinalUtil.FINAL_RESPONSE, resultJson);
        /* 查询数据 */
        return this.investigateUpdate(paramQuery, model);
    }

    /**
     * 批量操作
     * @param paramQuery    操作的条件
     * @param model 存储对象
     * @return  返回json数据
     */
    @RequestMapping("/investigateBatch")
    @ResponseBody
    public String investigateBatch(AtUsersInvestigateQuery paramQuery, Model model) {
        log.info("==考察行程批量操作==");
        String operType = paramQuery.getOperType();
        String[] ids = paramQuery.getIds();
        String info = ConstatFinalUtil.FINAL_OPER_SUCCESS;
        int totalCount = 0;
        int succedCount = 0;
        int failedCount = 0;
        if (StringUtils.isNotEmpty(operType)) {
            if (Objects.nonNull(ids) && ids.length > 0) {
                totalCount = ids.length;
                for (String idTemp : ids) {
                    try {
                        AtUsersInvestigateQuery paramQueryTemp = new AtUsersInvestigateQuery();
                        AtUsersInvestigate entity = paramQueryTemp.getEntity();
                        entity.setId(idTemp);
                        /* 根据id查询每一个 记录对象 */
                        AtUsersInvestigate dataDbResult = this.usersInvestigateService.findOne(paramQueryTemp);
                        if (dataDbResult != null) {
                            boolean dbFlag = false;
                            /* 催办 */
                            if (BaseQuery.FINAL_OPER_UPDATE_URGING.equalsIgnoreCase(operType)) {
                                /* 批量修改状态 */
                                dataDbResult.setUrgingNum(dataDbResult.getUrgingNum() + 1);
                                dbFlag = this.usersInvestigateService.updateById(dataDbResult);
                            }
                            if (dbFlag) {
                                succedCount ++;
                            } else {
                                failedCount ++;
                            }
                        }
                    } catch (Exception e) {
                        log.error("批量操作失败了,id:{}", idTemp, e);
                        failedCount ++;
                    }
                }
            } else {
                /* 未选择类型,ids */
                info = "ids为空";
            }
        } else {
            /* 操作类型未选择 */
            info = "操作类型未选择";
        }

        String messInfo = "批量操作日志:提示信息:${info}, 总条数:${totalCount},成功条数:${succedCount},失败条数:${failedCount}";
        Map<String,String> paramsMap = new HashMap<>(1);
        paramsMap.put("info", info);
        paramsMap.put("totalCount", String.valueOf(totalCount));
        paramsMap.put("succedCount", String.valueOf(succedCount));
        paramsMap.put("failedCount", String.valueOf(failedCount));
        messInfo = this.regexUtil.replaceOperator(messInfo, paramsMap);

        paramsMap = new HashMap<>(1);
        paramsMap.put(ConstatFinalUtil.FINAL_CONFIG_INFO_SUCCESS_PARAM1, messInfo);
        /* 查询数据 */
        JSONObject resultJson = this.proccedResponseJson(ConstatFinalUtil.FINAL_OPER_SUCCESS.equalsIgnoreCase(info), paramsMap);
        log.info("==结果:{}==", resultJson);
        return resultJson.toJSONString();
    }
}
